/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controladora.ControlTelaConfigLog;
import controladora.ControlaPaciente;
import logs.Log;
import persistencia.Pacientes;
import grafico.GraficoCC;
import grafico.GraficoIAC;
import grafico.GraficoIMC;
import grafico.GraficoRCQ;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import observer.Observador;
import propriedadesLog.PropriedadesLog;

/**
 *
 * @author Kdc
 */
public class TelaMenuPrincipal extends JFrame implements Observador{

    /**
     * Creates new form telaMenuPrincipal
     */
    
    Log log;
    ControlaPaciente cPaciente;
    Pacientes pacientes;
    PropriedadesLog propertiesLog;
    
    
    public TelaMenuPrincipal() {
        
        initComponents();

        pacientes = new Pacientes();
        
        cPaciente = new ControlaPaciente(pacientes);
        
        propertiesLog = new PropriedadesLog();
        
        try
        {
            log = propertiesLog.pegarLog();
            
        } catch (Exception ex)
        {
            Logger.getLogger(TelaMenuPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        
        
        pacientes.registrarObservador(this);
        
        this.setVisible(true);        
        this.setLocationRelativeTo(null);
        lbNPac.setText(String.valueOf(cPaciente.qtdPacientes()));
        
        
        
    }

    public Log getLog() {
        return log;
    }

    public void setLog(Log log) {
        this.log = log;
    }
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lbNPac = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jCadPaciente = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jShowPacientes = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        menuGraficoIMC = new javax.swing.JMenuItem();
        menuGraficoIAC = new javax.swing.JMenuItem();
        menuGraficoRCQ = new javax.swing.JMenuItem();
        menuGraficoCC = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Menu Principal");
        setBackground(new java.awt.Color(255, 255, 255));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel1.setText("Total de Pacientes Cadastrados:");

        lbNPac.setText("N_PAC");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 179, Short.MAX_VALUE)
                .addComponent(lbNPac)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel1)
                .addComponent(lbNPac))
        );

        jMenu3.setText("Arquivo");

        jMenuItem3.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        jMenuItem3.setText("Sair");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuBar1.add(jMenu3);

        jMenu1.setText("Cadastrar");
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu1MouseClicked(evt);
            }
        });
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jCadPaciente.setText("Paciente");
        jCadPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCadPacienteActionPerformed(evt);
            }
        });
        jMenu1.add(jCadPaciente);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Exibir");
        jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu2MouseClicked(evt);
            }
        });
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
            }
        });

        jShowPacientes.setText("Pacientes");
        jShowPacientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jShowPacientesActionPerformed(evt);
            }
        });
        jMenu2.add(jShowPacientes);

        jMenuBar1.add(jMenu2);

        jMenu5.setText("Gráficos");

        menuGraficoIMC.setText("Gráfico IMC");
        menuGraficoIMC.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                menuGraficoIMCMouseClicked(evt);
            }
        });
        menuGraficoIMC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuGraficoIMCActionPerformed(evt);
            }
        });
        jMenu5.add(menuGraficoIMC);

        menuGraficoIAC.setText("Gráfico IAC");
        menuGraficoIAC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuGraficoIACActionPerformed(evt);
            }
        });
        jMenu5.add(menuGraficoIAC);

        menuGraficoRCQ.setText("Gráfico RCQ");
        menuGraficoRCQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuGraficoRCQActionPerformed(evt);
            }
        });
        jMenu5.add(menuGraficoRCQ);

        menuGraficoCC.setText("Gráfico CC");
        menuGraficoCC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuGraficoCCActionPerformed(evt);
            }
        });
        jMenu5.add(menuGraficoCC);

        jMenuBar1.add(jMenu5);

        jMenu4.setText("Conf. de Log");

        jMenuItem1.setText("Configurar Log");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem1);

        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(252, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jShowPacientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jShowPacientesActionPerformed
        
        TelaListarPacientes t = new TelaListarPacientes(log, cPaciente);
 
    }//GEN-LAST:event_jShowPacientesActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        
//        int sair = JOptionPane.showConfirmDialog(rootPane, "Deseja Realmente Sair?");
//        
//        if(sair == 0)
//        {
            this.dispose();
            System.exit(0);
//        }
                
               
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jCadPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCadPacienteActionPerformed
        
        new TelaCadPaciente(null, cPaciente, log);          
        
        
    }//GEN-LAST:event_jCadPacienteActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        
        ControlTelaConfigLog controlMenuLog = new ControlTelaConfigLog(this);
        
         
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed

    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu2ActionPerformed

    }//GEN-LAST:event_jMenu2ActionPerformed

    private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseClicked
 
        if(log == null)
        {
            JOptionPane.showMessageDialog(this, "Selecionar Tipo de Log Primeiro!");
        }
    }//GEN-LAST:event_jMenu1MouseClicked

    private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu2MouseClicked
 
        if(log == null)
        {
            JOptionPane.showMessageDialog(this, "Selecionar Tipo de Log Primeiro!");
        }
    }//GEN-LAST:event_jMenu2MouseClicked

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
       
    }//GEN-LAST:event_formWindowGainedFocus

    private void menuGraficoIMCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGraficoIMCActionPerformed
        
        new GraficoIMC(pacientes);
        
    }//GEN-LAST:event_menuGraficoIMCActionPerformed

    private void menuGraficoIACActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGraficoIACActionPerformed
 
        new GraficoIAC(pacientes);
        
    }//GEN-LAST:event_menuGraficoIACActionPerformed

    private void menuGraficoRCQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGraficoRCQActionPerformed
 
        new GraficoRCQ(pacientes);
        
    }//GEN-LAST:event_menuGraficoRCQActionPerformed

    private void menuGraficoCCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGraficoCCActionPerformed
         
        new GraficoCC(pacientes);
        
    }//GEN-LAST:event_menuGraficoCCActionPerformed

    private void menuGraficoIMCMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_menuGraficoIMCMouseClicked
    {//GEN-HEADEREND:event_menuGraficoIMCMouseClicked

        if(log == null)
        {
            JOptionPane.showMessageDialog(this, "Selecionar Tipo de Log Primeiro!");
        }
        
    }//GEN-LAST:event_menuGraficoIMCMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem jCadPaciente;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JMenuItem jShowPacientes;
    private javax.swing.JLabel lbNPac;
    private javax.swing.JMenuItem menuGraficoCC;
    private javax.swing.JMenuItem menuGraficoIAC;
    private javax.swing.JMenuItem menuGraficoIMC;
    private javax.swing.JMenuItem menuGraficoRCQ;
    // End of variables declaration//GEN-END:variables

    public JLabel getLbNPac() {
        return lbNPac;
    }

    public void setLbNPac(JLabel lbNPac) {
        this.lbNPac = lbNPac;
    }

    @Override
    public void atualizar() {
        
        lbNPac.setText(String.valueOf(cPaciente.qtdPacientes()));
        
    }

        public static void main(String[] args) {
        
//        Controladora.ControlaPaciente cp = new ControlaPaciente();
        
       new TelaMenuPrincipal();

        
        
        
    }
    
}
